    // MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include <atlwince.h>
#include <atlcrack.h>

#include <memory>

#include "Options.h"
#include "ListView.h"
#include "IController.h"

class ListModel;

class CMainFrame : public CFrameWindowImpl<CMainFrame>
                 , public CUpdateUI<CMainFrame>
                 , public CMessageFilter
                 , public CAppWindow<CMainFrame>
                 , public CIdleHandler
{
public:
    CMainFrame()
    {
        listView = std::auto_ptr<ListView>( new ListView() );
    }

	DECLARE_APP_FRAME_CLASS(NULL, IDR_MAINFRAME, L"Software\\pm")

	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual BOOL OnIdle();

	BEGIN_UPDATE_UI_MAP(CMainFrame)
	END_UPDATE_UI_MAP()

	BEGIN_MSG_MAP_EX(CMainFrame)
        
        MESSAGE_HANDLER(WM_CREATE, OnCreate)
        MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
        NOTIFY_CODE_HANDLER(NM_CLICK, OnItemClick)
        MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnKey)
        COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
		COMMAND_ID_HANDLER(ID_FILE_NEW, OnFileNew)
        COMMAND_ID_HANDLER(ID_FILE_DELETE, OnFileDelete)
		COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
        COMMAND_ID_HANDLER(ID_APP_OPTIONS, OnOptions)
        MSG_WM_SIZE(OnSize)
        MSG_WM_CLOSE(OnClose)
        CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
		CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
        CHAIN_MSG_MAP(CAppWindow<CMainFrame>)
        REFLECT_NOTIFICATIONS()
	END_MSG_MAP()

    LRESULT OnItemClick(int item, LPNMHDR lpNMHDR, BOOL bHandled);
    LRESULT OnItemActivate(int item, LPNMHDR lpNMHDR, BOOL bHandled);

	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
    void OnSize(UINT, const CSize&);

    void OnClose() { 
        DestroyWindow();
        PostQuitMessage(0);
    }

	LRESULT OnContextMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

	LRESULT OnPopMenu(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnOptions(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT OnFileDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

    void OpenItem(int item);

	LRESULT OnKey(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/);

protected:
    std::auto_ptr<ListModel> model;
    std::auto_ptr<ListView> listView;

    std::auto_ptr<Options> options;

//    std::wstring workingDir;
};
